package org.qengine.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.qengine.entity.DataDictEntity;
import org.qengine.entity.DicTypeEntity;
import org.qengine.entity.UserAnswersEntity;
import org.qengine.service.UserAnswersService;
import org.qengine.service.PaperInfoService;
import org.qengine.vo.DataDictVo;
import org.qengine.vo.UserAnswerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("userAnswers/")
public class UserAnswersController {

    @Autowired
    private UserAnswersService userAnswersService;
    @Autowired
    private PaperInfoService paperInfoService;
    @PostMapping("/add")
    public String add(@RequestBody UserAnswersEntity answer) {
        paperInfoService.updateAnsStatus(answer);
        paperInfoService.updateScore(answer);
        Integer i =userAnswersService.add(answer);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }

    }
    @PostMapping("/delete/{id}")
    public String deleteById(@PathVariable Long id){
        Integer i =userAnswersService.delete(id);
        if(i>0){
            return "success";
        }
        else {
            return "fail";
        }
    }
    @PostMapping("/getByUserId")//通过学号查找写过的卷子（学生答案）
    public IPage<UserAnswersEntity> search(@RequestBody UserAnswerVo userAnswerVo){
        return userAnswersService.search(userAnswerVo);
    }




}
